package org.hgg.workflow.core;

import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;

/**
 * @author Jarvis
 * @date 2023/12/27 23:27
 */
public class Node<T, R> {

    private T name;
    private Set<Node<T, R>> parents;
    private Set<Node<T, R>> children;

    public Node(T name) {
        this.name = name;
        this.parents = new LinkedHashSet<>();
        this.children = new LinkedHashSet<>();
    }

    public Set<Node<T, R>> getParents() {
        return parents;
    }

    public Set<Node<T, R>> getChildren() {
        return children;
    }

    public int getInDegree() {
        return parents.size();
    }

    @Override
    public String toString() {
        return "Node{" +
                "name=" + name +
                '}';
    }

    public T getName() {
        return name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Node<?, ?> node = (Node<?, ?>) o;
        return Objects.equals(name, node.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }
}
